import bisect
class Solution(object):
    def maxRunTime(self, n, batteries):
        batteries.sort()
        m = len(batteries)
        prefix = [0] * (m + 1)
        for i in range(m):
            prefix[i + 1] = prefix[i] + batteries[i]
        while n > 0:
            now_max = prefix[m] // n
            if now_max >= batteries[m - 1]:
                break
            next_m = bisect.bisect_left(batteries, now_max)
            n -= (m - next_m)
            m = next_m
        return now_max


data = Solution()
n = 4
batteries = [10, 20, 10, 20, 10000]
print(data.maxRunTime(n, batteries))